<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Aria: directMotionExample.cpp</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.0</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('directMotionExample_8cpp-example.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">directMotionExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Sends a sequence of motion commands directly to the robot using <a class="el" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a>'s direct motion command methods. This demo starts up the robot in its own thread, then calls a series of the motion commands methods in <a class="el" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a> to simply send commands directly to the robot (rather than using e.g. <a class="el" href="classArAction.html" title="Base class for actions.">ArAction</a> objects.)</p>
<p>Note that if you want to stop direct motion commands and let ArActions take over, you must call <a class="el" href="classArRobot.html#a5b1b947ef2e28d171f023b1bbe5d02a9" title="Clears what direct motion commands have been given, so actions work.">ArRobot::clearDirectMotion()</a> (otherwise <a class="el" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a> may continue sending motion commands that conflict with the requests of the action resolver). See the section on motion commands and actions for details.</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &quot;Aria.h&quot;</span>

<span class="comment">/*</span>
<span class="comment">  This is a connection handler class, to demonstrate how to run code in</span>
<span class="comment">  response to events such as the program connecting an disconnecting</span>
<span class="comment">  from the robot.</span>
<span class="comment">*/</span>
<span class="keyword">class </span>ConnHandler
{
<span class="keyword">public</span>:
  <span class="comment">// Constructor</span>
  ConnHandler(<a name="_a0"></a><a class="code" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a> *robot);
  <span class="comment">// Destructor, its just empty</span>
  ~ConnHandler(<span class="keywordtype">void</span>) {}
  <span class="comment">// to be called if the connection was made</span>
  <span class="keywordtype">void</span> connected(<span class="keywordtype">void</span>);
  <span class="comment">// to call if the connection failed</span>
  <span class="keywordtype">void</span> connFail(<span class="keywordtype">void</span>);
  <span class="comment">// to be called if the connection was lost</span>
  <span class="keywordtype">void</span> disconnected(<span class="keywordtype">void</span>);
<span class="keyword">protected</span>:
  <span class="comment">// robot pointer</span>
  <a class="code" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a> *myRobot;
  <span class="comment">// the functor callbacks</span>
  <a name="_a1"></a><a class="code" href="classArFunctorC.html">ArFunctorC&lt;ConnHandler&gt;</a> myConnectedCB;
  <a class="code" href="classArFunctorC.html">ArFunctorC&lt;ConnHandler&gt;</a> myConnFailCB;
  <a class="code" href="classArFunctorC.html">ArFunctorC&lt;ConnHandler&gt;</a> myDisconnectedCB;
};

ConnHandler::ConnHandler(<a class="code" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a> *robot) :
  myConnectedCB(this, &amp;ConnHandler::connected),  
  myConnFailCB(this, &amp;ConnHandler::connFail),
  myDisconnectedCB(this, &amp;ConnHandler::disconnected)

{
  myRobot = robot;
  myRobot-&gt;<a name="a2"></a><a class="code" href="classArRobot.html#aa2d179de23b698c94d5bfc72eccdc4f9" title="Adds a connect callback.">addConnectCB</a>(&amp;myConnectedCB, <a name="a3"></a><a class="code" href="classArListPos.html#adb42d52c70a646c5698c5513cd25bbd0a7573a55fbcdb54b1768e9ce574407d15" title="place item first in the list">ArListPos::FIRST</a>);
  myRobot-&gt;addFailedConnectCB(&amp;myConnFailCB, <a class="code" href="classArListPos.html#adb42d52c70a646c5698c5513cd25bbd0a7573a55fbcdb54b1768e9ce574407d15" title="place item first in the list">ArListPos::FIRST</a>);
  myRobot-&gt;addDisconnectNormallyCB(&amp;myDisconnectedCB, <a class="code" href="classArListPos.html#adb42d52c70a646c5698c5513cd25bbd0a7573a55fbcdb54b1768e9ce574407d15" title="place item first in the list">ArListPos::FIRST</a>);
  myRobot-&gt;addDisconnectOnErrorCB(&amp;myDisconnectedCB, <a class="code" href="classArListPos.html#adb42d52c70a646c5698c5513cd25bbd0a7573a55fbcdb54b1768e9ce574407d15" title="place item first in the list">ArListPos::FIRST</a>);
}

<span class="comment">// just exit if the connection failed</span>
<span class="keywordtype">void</span> ConnHandler::connFail(<span class="keywordtype">void</span>)
{
  printf(<span class="stringliteral">&quot;directMotionDemo connection handler: Failed to connect.\n&quot;</span>);
  myRobot-&gt;stopRunning();
  <a name="a4"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17" title="Shutdown all Aria processes/threads, call exit callbacks, and exit the program.">Aria::exit</a>(1);
  <span class="keywordflow">return</span>;
}

<span class="comment">// turn on motors, and off sonar, and off amigobot sounds, when connected</span>
<span class="keywordtype">void</span> ConnHandler::connected(<span class="keywordtype">void</span>)
{
  printf(<span class="stringliteral">&quot;directMotionDemo connection handler: Connected\n&quot;</span>);
  myRobot-&gt;comInt(<a name="a5"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4a891b21e6cabc8a2296c8bceca20be779" title="int, enable (1) or disable (0) sonar">ArCommands::SONAR</a>, 0);
  myRobot-&gt;comInt(<a name="a6"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4aa8d799cced5def80525936119963aad4" title="int, enable (1) or disable (0) motors">ArCommands::ENABLE</a>, 1);
  myRobot-&gt;comInt(<a name="a7"></a><a class="code" href="classArCommands.html#a9a31f904a95bbc31d8b33c6637100cc4a7a256695b7937192e88c976d2fd106e5" title="int, AmigoBot (old H8 model) specific, enable(1) or diable(0) sound">ArCommands::SOUNDTOG</a>, 0);
}

<span class="comment">// lost connection, so just exit</span>
<span class="keywordtype">void</span> ConnHandler::disconnected(<span class="keywordtype">void</span>)
{
  printf(<span class="stringliteral">&quot;directMotionDemo connection handler: Lost connection, exiting program.\n&quot;</span>);
  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17" title="Shutdown all Aria processes/threads, call exit callbacks, and exit the program.">Aria::exit</a>(0);
}



<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) 
{
  <a name="a8"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73" title="Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...">Aria::init</a>();
  
  <a name="_a9"></a><a class="code" href="classArArgumentParser.html" title="Parse and store program command-line arguments for use by other ARIA classes.">ArArgumentParser</a> argParser(&amp;argc, argv);
  argParser.loadDefaultArguments();


  <a class="code" href="classArRobot.html" title="Central class for communicating with and operating the robot.">ArRobot</a> robot;
  <a name="_a10"></a><a class="code" href="classArRobotConnector.html" title="Connect to robot or simulator based on program command line parameters.">ArRobotConnector</a> con(&amp;argParser, &amp;robot);

  <span class="comment">// the connection handler from above</span>
  ConnHandler ch(&amp;robot);

  <span class="keywordflow">if</span>(!<a name="a11"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1" title="Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())">Aria::parseArgs</a>())
  {
    <a name="a12"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42" title="Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())">Aria::logOptions</a>();
    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17" title="Shutdown all Aria processes/threads, call exit callbacks, and exit the program.">Aria::exit</a>(1);
    <span class="keywordflow">return</span> 1;
  }

  <span class="keywordflow">if</span>(!con.connectRobot())
  {
    <a name="a13"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce" title="Log a message, with formatting and variable number of arguments.">ArLog::log</a>(<a name="a14"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1" title="Use normal logging.">ArLog::Normal</a>, <span class="stringliteral">&quot;directMotionExample: Could not connect to the robot. Exiting.&quot;</span>);

    <span class="keywordflow">if</span>(argParser.checkHelpAndWarnUnparsed()) 
    {
      <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42" title="Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())">Aria::logOptions</a>();
    }
    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17" title="Shutdown all Aria processes/threads, call exit callbacks, and exit the program.">Aria::exit</a>(1);
    <span class="keywordflow">return</span> 1;
  }

  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce" title="Log a message, with formatting and variable number of arguments.">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1" title="Use normal logging.">ArLog::Normal</a>, <span class="stringliteral">&quot;directMotionExample: Connected.&quot;</span>);

  <span class="keywordflow">if</span>(!<a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1" title="Parses the arguments for the program (calls all the callbacks added with addParseArgsCB())">Aria::parseArgs</a>() || !argParser.checkHelpAndWarnUnparsed())
  {
    <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42" title="Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB())">Aria::logOptions</a>();
    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17" title="Shutdown all Aria processes/threads, call exit callbacks, and exit the program.">Aria::exit</a>(1);
  }

  <span class="comment">// Run the robot processing cycle in its own thread. Note that after starting this</span>
  <span class="comment">// thread, we must lock and unlock the ArRobot object before and after</span>
  <span class="comment">// accessing it.</span>
  robot.<a name="a15"></a><a class="code" href="classArRobot.html#a3c3d878cfd11a2ef91230005a83bfcaa" title="Starts the instance to do processing in its own new thread.">runAsync</a>(<span class="keyword">false</span>);


  <span class="comment">// Send the robot a series of motion commands directly, sleeping for a </span>
  <span class="comment">// few seconds afterwards to give the robot time to execute them.</span>
  printf(<span class="stringliteral">&quot;directMotionExample: Setting rot velocity to 100 deg/sec then sleeping 3 seconds\n&quot;</span>);
  robot.<a name="a16"></a><a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a17"></a><a class="code" href="classArRobot.html#a613157de1936d0c34ed73e32787ae661" title="Sets the rotational velocity.">setRotVel</a>(100);
  robot.<a name="a18"></a><a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a name="a19"></a><a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(3*1000);
  printf(<span class="stringliteral">&quot;Stopping\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a613157de1936d0c34ed73e32787ae661" title="Sets the rotational velocity.">setRotVel</a>(0);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(200);

  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to go 300 mm on left wheel and 100 mm on right wheel for 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a20"></a><a class="code" href="classArRobot.html#a887e87b779740ad024f65c6ef67394cc" title="Sets the velocity of the wheels independently.">setVel2</a>(300, 100);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a name="_a21"></a><a class="code" href="classArTime.html" title="A class for time readings and measuring durations.">ArTime</a> start;
  start.<a name="a22"></a><a class="code" href="classArTime.html#a7c269e161c8e7cb56bde73dea501a619" title="Resets the time.">setToNow</a>();
  <span class="keywordflow">while</span> (1)
  {
    robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
    <span class="keywordflow">if</span> (start.<a name="a23"></a><a class="code" href="classArTime.html#abfac503dbf12dac57c8dc133d0b034a1" title="Gets the number of milliseconds since the given timestamp to this one.">mSecSince</a>() &gt; 5000)
    {
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }   
    robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
    <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(50);
  }
  
  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to move forwards one meter, then sleeping 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a24"></a><a class="code" href="classArRobot.html#a09016d00e1f3ac9a502344d9e2cd548e" title="Move the given distance forward/backwards.">move</a>(1000);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  start.<a class="code" href="classArTime.html#a7c269e161c8e7cb56bde73dea501a619" title="Resets the time.">setToNow</a>();
  <span class="keywordflow">while</span> (1)
  {
    robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
    <span class="keywordflow">if</span> (robot.<a name="a25"></a><a class="code" href="classArRobot.html#ab74884fb32bdc6e006b556f131343880" title="Sees if the robot is done moving the previously given move.">isMoveDone</a>())
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Finished distance\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    <span class="keywordflow">if</span> (start.<a class="code" href="classArTime.html#abfac503dbf12dac57c8dc133d0b034a1" title="Gets the number of milliseconds since the given timestamp to this one.">mSecSince</a>() &gt; 5000)
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Distance timed out\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }   
    robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
    <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(50);
  }
  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to move backwards one meter, then sleeping 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a09016d00e1f3ac9a502344d9e2cd548e" title="Move the given distance forward/backwards.">move</a>(-1000);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  start.<a class="code" href="classArTime.html#a7c269e161c8e7cb56bde73dea501a619" title="Resets the time.">setToNow</a>();
  <span class="keywordflow">while</span> (1)
  {
    robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
    <span class="keywordflow">if</span> (robot.<a class="code" href="classArRobot.html#ab74884fb32bdc6e006b556f131343880" title="Sees if the robot is done moving the previously given move.">isMoveDone</a>())
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Finished distance\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    <span class="keywordflow">if</span> (start.<a class="code" href="classArTime.html#abfac503dbf12dac57c8dc133d0b034a1" title="Gets the number of milliseconds since the given timestamp to this one.">mSecSince</a>() &gt; 10000)
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Distance timed out\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
    <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(50);
  }
  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to turn to 180, then sleeping 4 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a26"></a><a class="code" href="classArRobot.html#afbbe47b4351cc9baf2559d188803ee72" title="Sets the heading.">setHeading</a>(180);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  start.<a class="code" href="classArTime.html#a7c269e161c8e7cb56bde73dea501a619" title="Resets the time.">setToNow</a>();
  <span class="keywordflow">while</span> (1)
  {
    robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
    <span class="keywordflow">if</span> (robot.<a name="a27"></a><a class="code" href="classArRobot.html#a189ad51451c91c3c5b9a67a5c33b7b4d" title="Sees if the robot is done changing to the previously given setHeading.">isHeadingDone</a>(5))
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Finished turn\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    <span class="keywordflow">if</span> (start.<a class="code" href="classArTime.html#abfac503dbf12dac57c8dc133d0b034a1" title="Gets the number of milliseconds since the given timestamp to this one.">mSecSince</a>() &gt; 5000)
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Turn timed out\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
    <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(100);
  }
  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to turn to 90, then sleeping 2 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#afbbe47b4351cc9baf2559d188803ee72" title="Sets the heading.">setHeading</a>(90);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  start.<a class="code" href="classArTime.html#a7c269e161c8e7cb56bde73dea501a619" title="Resets the time.">setToNow</a>();
  <span class="keywordflow">while</span> (1)
  {
    robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
    <span class="keywordflow">if</span> (robot.<a class="code" href="classArRobot.html#a189ad51451c91c3c5b9a67a5c33b7b4d" title="Sees if the robot is done changing to the previously given setHeading.">isHeadingDone</a>(5))
    {
      printf(<span class="stringliteral">&quot;directMotionExample: Finished turn\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    <span class="keywordflow">if</span> (start.<a class="code" href="classArTime.html#abfac503dbf12dac57c8dc133d0b034a1" title="Gets the number of milliseconds since the given timestamp to this one.">mSecSince</a>() &gt; 5000)
    {
      printf(<span class="stringliteral">&quot;directMotionExample: turn timed out\n&quot;</span>);
      robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
      <span class="keywordflow">break</span>;
    }
    robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
    <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(100);
  }
  printf(<span class="stringliteral">&quot;directMotionExample: Setting vel2 to 200 mm/sec on both wheels, then sleeping 3 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a887e87b779740ad024f65c6ef67394cc" title="Sets the velocity of the wheels independently.">setVel2</a>(200, 200);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(3000);
  printf(<span class="stringliteral">&quot;directMotionExample: Stopping the robot, then sleeping for 2 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a28"></a><a class="code" href="classArRobot.html#ac354fe63f9e58b33343f38923f1588fd" title="Stops the robot.">stop</a>();
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(2000);
  printf(<span class="stringliteral">&quot;directMotionExample: Setting velocity to 200 mm/sec then sleeping 3 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a29"></a><a class="code" href="classArRobot.html#ac4c369f0f8d8a41f2b3f2290bdcbb03c" title="Sets the velocity.">setVel</a>(200);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(3000);
  printf(<span class="stringliteral">&quot;directMotionExample: Stopping the robot, then sleeping for 2 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#ac354fe63f9e58b33343f38923f1588fd" title="Stops the robot.">stop</a>();
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(2000);
  printf(<span class="stringliteral">&quot;directMotionExample: Setting vel2 with 0 on left wheel, 200 mm/sec on right, then sleeping 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a887e87b779740ad024f65c6ef67394cc" title="Sets the velocity of the wheels independently.">setVel2</a>(0, 200);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(5000);
  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to rotate at 50 deg/sec then sleeping 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a613157de1936d0c34ed73e32787ae661" title="Sets the rotational velocity.">setRotVel</a>(50);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(5000);
  printf(<span class="stringliteral">&quot;directMotionExample: Telling the robot to rotate at -50 deg/sec then sleeping 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a613157de1936d0c34ed73e32787ae661" title="Sets the rotational velocity.">setRotVel</a>(-50);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(5000);
  printf(<span class="stringliteral">&quot;directMotionExample: Setting vel2 with 0 on both wheels, then sleeping 3 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a887e87b779740ad024f65c6ef67394cc" title="Sets the velocity of the wheels independently.">setVel2</a>(0, 0);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(3000);
  printf(<span class="stringliteral">&quot;directMotionExample: Now having the robot change heading by -125 degrees, then sleeping for 6 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a name="a30"></a><a class="code" href="classArRobot.html#a033038331dbe4cbaabad2d0bc67653f0" title="Sets the delta heading.">setDeltaHeading</a>(-125);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(6000);
  printf(<span class="stringliteral">&quot;directMotionExample: Now having the robot change heading by 45 degrees, then sleeping for 6 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a033038331dbe4cbaabad2d0bc67653f0" title="Sets the delta heading.">setDeltaHeading</a>(45);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(6000);
  printf(<span class="stringliteral">&quot;directMotionExample: Setting vel2 with 200 on left wheel, 0 on right wheel, then sleeping 5 seconds\n&quot;</span>);
  robot.<a class="code" href="classArRobot.html#a5aecc7ac998c9a31b82fdb904efa8609" title="Lock the robot instance.">lock</a>();
  robot.<a class="code" href="classArRobot.html#a887e87b779740ad024f65c6ef67394cc" title="Sets the velocity of the wheels independently.">setVel2</a>(200, 0);
  robot.<a class="code" href="classArRobot.html#a403d9de010dc2b8d478cd0b14b2d9491" title="Unlock the robot instance.">unlock</a>();
  <a class="code" href="classArUtil.html#a4dfb878a3f9123b8dd96ae05b2fd94cb" title="Sleep for the given number of milliseconds.">ArUtil::sleep</a>(5000);

  printf(<span class="stringliteral">&quot;directMotionExample: Done, exiting.\n&quot;</span>);
  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17" title="Shutdown all Aria processes/threads, call exit callbacks, and exit the program.">Aria::exit</a>(0);
  <span class="keywordflow">return</span> 0;
}

</pre></div> </div><!-- contents -->
</div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Tue Nov 4 2014 09:55:43 for Aria by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
